#include <iostream>
using namespace std;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  for (cin >> T; T; T--) {
    int n, x;

    cin >> n >> x;

    int or_sum = 0;

    for (int i = 0; i < n - 1; i++) {
      if ((x & i) == i) {
        or_sum |= i;
        cout << i << " ";
      } else {
        cout << 0 << " ";
      }
    }

    if ((x & (n - 1)) == (n - 1) && (or_sum | (n - 1)) == x) {
      cout << n - 1 << "\n";
    } else {
      cout << (x ^ or_sum) << "\n";
    }
  }
  return 0;
}